import { HttpCode, Injectable } from '@nestjs/common';
import { commentDto } from '../dto/comment.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { commentEntity } from '../entities/comment.entity';
import { Repository } from 'typeorm';

@Injectable()
export class CommentService {
  constructor(@InjectRepository(commentEntity) private commentModel: Repository<commentEntity>) {}
  /**
   * @author nie
   * @description 发布文章
   * @email a896211755@gmail.com
   */
  async public(data: commentDto, user_id: number) {
    let val = new commentEntity();
    val.user_id = user_id;
    val.Content = data.content;
    val.info_id = data.Information_id
    val.reply_comment_id = data.comment_id ;
    return await this.commentModel.save(val);
  }

  /**
  * @author nie
  * @description 根据info_id获取下面的评论
  * @email a896211755@gmail.com
  */
 
 async commentListWithInfoIdOrUserId(id :number,type :1|2){
  console.log(id)
  if(type == 1){
    return await this.commentModel.find({where:{
      
      info_id:id,
  },
   select:['Content','createdDate','goods','reply_comment_id','info_id'],
}
  )
  }else{
    return await this.commentModel.find({where:{
      user_id:id,
  }})
  }
     
 }
}
